package com.cssy.yd.logic.web;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.jxls.transformer.XLSTransformer;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cssy.authority.service.IScUserRolewhPlaceService;
import com.cssy.base.web.BaseController;
import com.cssy.base.web.BodyMsg;
import com.cssy.yd.logic.entity.LogicPoWareDO;
import com.cssy.yd.logic.entity.LogicPoWareItemBatchDO;
import com.cssy.yd.logic.entity.LogicPoWareItemDO;
import com.cssy.yd.logic.entity.LogicProGetApplyDO;
import com.cssy.yd.logic.entity.LogicProGetApplyItemDO;
import com.cssy.yd.logic.entity.LogicSkReturnDO;
import com.cssy.yd.logic.entity.LogicSkReturnItemDO;
import com.cssy.yd.logic.service.ILogicProGetApplyItemService;
import com.cssy.yd.logic.service.ILogicProGetApplyService;
import com.cssy.yd.logic.util.SqlUtil;
import com.plat.exception.SyBaseException;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchCondition;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.GlobalResLoader;
import com.plat.util.OperationFlag;
import com.plat.util.SessionUtil;
import com.plat.util.json.OutJsonGrid;

@Controller
@RequestMapping("/yd/logic/progetapply")
public class LogicProGetApplyController extends
		BaseController<LogicProGetApplyDO> {

	private static final String MANAGER = "/yd/logic/proget/ApplyManager";
	private static final String EIDT = "/yd/logic/proget/ApplyOperation";// 添加、修改、显示页面

	@Resource(name = "logicProGetApplyService")
	private ILogicProGetApplyService logicProGetApplyService;

	@Resource(name = "logicProGetApplyItemService")
	private ILogicProGetApplyItemService logicProGetApplyItemService;
	
	@Resource(name="scUserRolePlaceService")
	private IScUserRolewhPlaceService scUserRolePlaceService;
	@Override
	public String manager(HttpServletRequest request, Model model)
			throws Exception {
		return MANAGER;
	}

	@Override
	public void list(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		JqGridHandler hander = new JqGridHandler(request);
		SearchConditions scs = new SearchConditions();
		hander.getWheres(scs);
		 if(scs.getOrderBy()==null||"".equals(scs.getOrderBy()))
			 scs.setOrderBy("dctime desc");
		scs.addCondition("state","0",SearchCondition.OP_EQUAL);
		SearchResult result = logicProGetApplyService.findListByExample(scs);
		OutJsonGrid out = new OutJsonGrid(result);
		out.printJSon(response);
	}

	@SuppressWarnings("unchecked")
	@Override
	public String operationForm(HttpServletRequest request,
			@PathVariable String id, @PathVariable String flag, Model model)
			throws Exception {
		model.addAttribute("wh",SqlUtil.sqlUtil.roleWH(request, scUserRolePlaceService));
		if (OperationFlag.ADD.equals(flag)) {// 我新增加时操作
			model.addAttribute("viewflag", "add");
			model.addAttribute("xx", 1);// 标示能不能修改内容
		} else {
			LogicProGetApplyDO oi = logicProGetApplyService.findListById(id);
			/*SearchConditions scs = new SearchConditions();
			scs.addCondition("get_pro_id",oi.getId(),SearchCondition.OP_EQUAL);
			scs.setRemovedProperty(null);
			scs.setOrderBy("code");
			List<LogicProGetApplyItemDO> loiilist = logicProGetApplyItemService.findListByExample(scs).getResults();*/
			if (oi.getBillStatus() == 0) {
				model.addAttribute("xx", 1);// 标示能不能修改内容
				model.addAttribute("viewflag", "tijiao");
			} else {
				model.addAttribute("xx", 2);// 标示能不能修改内容
			}
			if (oi.getBillStatus() == 2) {
				model.addAttribute("viewflag", "tongguo");
			}
			if (oi.getBillStatus() == 1) {
				model.addAttribute("viewflag", "shenpi");
			}
			model.addAttribute("oi", oi);
			//model.addAttribute("axxJson", loiilist);
		}
		return EIDT;
	}

	@RequestMapping("/griditems")
	public void griditems(HttpServletRequest request,HttpServletResponse response) throws Exception{
		String id = request.getParameter("id");
		if(StringUtils.isNotBlank(id)){
			LogicProGetApplyDO oi = logicProGetApplyService.findListById(id);
			SearchConditions scs = new SearchConditions();
			scs.addCondition("get_pro_id",oi.getId(),SearchCondition.OP_EQUAL);
			scs.setRemovedProperty(null);
			scs.setOrderBy("code");
			List<LogicProGetApplyItemDO> loiilist = logicProGetApplyItemService.findListByExample(scs).getResults();
			OutJsonGrid out = new OutJsonGrid(loiilist);
			out.printJSon(response);
		}
	}
	
	@Override
	public Map<String, Object> save(HttpServletRequest request,
			LogicProGetApplyDO curAP, BindingResult result, Model model)
			throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
		try {
			logicProGetApplyService.proGetSave(request,curAP);
			bodyMap.isSuccess();
			bodyMap.configWebInfor(GlobalResLoader.getOpsuccess());
		} catch (SyBaseException e) {
			e.printStackTrace();
			bodyMap.isFail();
			bodyMap.configWebInfor(GlobalResLoader.getOpfailed()
					+ e.getMessage());
		}
		return bodyMap.modelMap;
	}

	@Override
	public Map<String, Object> delete(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
		try {
			String ids = request.getParameter("ids");
			String[] fields = ids.split(",");
			for (String field : fields) {
				LogicProGetApplyDO lout=logicProGetApplyService.findListById(field);
				lout.setRemoved(Short.parseShort("1"));
				logicProGetApplyService.update(lout, SessionUtil.getUser(request));
			}

			bodyMap.isSuccess(GlobalResLoader.getOpsuccess());
		} catch (Exception e) {
			e.printStackTrace();
			bodyMap.isFail(GlobalResLoader.getOpfailed() + e.getMessage());
		}
		return bodyMap.modelMap;
	}
	
	
	@RequestMapping(value = "/updateState")
	@ResponseBody
	public Map<String,String> updateState(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		Map<String, String> map=new HashMap<String, String>();
		try{
			String ids = request.getParameter("rows");
			if(ids!=null&&!"".equals(ids)){
				LogicProGetApplyDO lot=logicProGetApplyService.findListById(ids);
				if(lot.getId()!=null){
					lot.setBillStatus(Short.parseShort("0"));
					logicProGetApplyService.update(lot, SessionUtil.getUser(request));
					map.put("msg", "SUCCESS");
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			map.put("msg", "ERROR");
		}
		return map;
	}
	
//	@RequestMapping(value = "/exportExcel")
//	public void printer(HttpServletRequest request, HttpServletResponse response) throws Exception{
//		String id = request.getParameter("id");
//		LogicProGetApplyDO proget = new LogicProGetApplyDO();
//		List<LogicProGetApplyItemDO> itemlist = new ArrayList<LogicProGetApplyItemDO>();
//		if(!"".equals(id)&&id!=null){
//			proget =logicProGetApplyService.findListById(id);
//		}
//		if(proget.getId()!=null){
//			SearchConditions scs = new SearchConditions();
//			scs.addCondition("get_pro_id", proget.getId(),SearchCondition.OP_EQUAL);
//			scs.setLimitPage(false);
//			scs.setRemovedProperty(null);
//			scs.setOrderBy("code");
//			itemlist =logicProGetApplyItemService.findListByExample(scs).getResults();
//		}
//		HSSFWorkbook wb = new HSSFWorkbook();//建立新HSSFWorkbook对象  
//		HSSFSheet sheet = wb.createSheet("new sheet");//建立新的sheet对象  
//		sheet.setDefaultRowHeight((short)100);
//		sheet.getPrintSetup().setPaperSize(HSSFPrintSetup.A4_PAPERSIZE); // 纸张
//		sheet.getPrintSetup().setLandscape(true);
//		sheet.setDisplayGridlines(false);
//		sheet.setPrintGridlines(false);
//		sheet.setMargin(HSSFSheet.TopMargin,( double ) 0.2 ); // 上边距
//	//	sheet.setMargin(HSSFSheet.BottomMargin,( double ) 0.2 ); // 下边距
//		sheet.setMargin(HSSFSheet.LeftMargin,( double ) 0.2 ); // 左边距
//		sheet.setMargin(HSSFSheet.RightMargin,( double ) 0.2 ); // 右边距
//		if(itemlist.size()>0){
//			HSSFCellStyle style = wb.createCellStyle();      
//			style.setBorderBottom(HSSFCellStyle.BORDER_DOTTED);//下边框       
//			style.setBorderLeft(HSSFCellStyle.BORDER_DOTTED);//左边框       
//			style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框       
//			style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
//			style.setBorderBottom((short) 1);
//			style.setBorderLeft((short) 1);
//			style.setBorderRight((short) 1);
//			style.setBorderTop((short) 1);
//			HSSFFont font = wb.createFont();
//			font.setFontName("宋体");
//			font.setFontHeightInPoints((short) 10);
//			style.setFont(font);
//			style.setAlignment((short) 2);
//			style.setVerticalAlignment((short) 1l);
//			
//			HSSFCellStyle style1 = wb.createCellStyle();
//			style1.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 指定单元格居中对齐 
//			style1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 指定单元格垂直居中对齐
//			HSSFFont font1 = wb.createFont();
//			font1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//			font1.setFontHeightInPoints((short) 14);
//			font1.setFontName("宋体");
//			style1.setFont(font1);
//			
//
//			HSSFCellStyle style2 = wb.createCellStyle();
//			style2.setFont(font);
//			style2.setWrapText(false);  
//			
//			HSSFCellStyle style3 = wb.createCellStyle();   
//			style3.setBorderBottom(HSSFCellStyle.BORDER_DOTTED);//下边框       
//			style3.setBorderLeft(HSSFCellStyle.BORDER_DOTTED);//左边框       
//			style3.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框       
//			style3.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
//			style3.setBorderBottom((short) 1);
//			style3.setBorderLeft((short) 1);
//			style3.setBorderRight((short) 1);
//			style3.setBorderTop((short) 1);
//			style3.setFont(font);
//			
//			HSSFRow row1 = sheet.createRow((short)0);//建立新行
//			Region region = new Region(0,(short) 0, 0, (short) 8);//指定合并区域
//			sheet.addMergedRegion(region);
//			HSSFCell cell1 = row1.createCell((short)0);
//			cell1.setCellValue("吉林华微斯帕克电气有限公司");
//			cell1.setCellStyle(style1);
//			
//			HSSFRow row2 = sheet.createRow((short)1);//建立新行
//			Region region1 = new Region(1,(short) 0, 1, (short) 8);//指定合并区域
//			sheet.addMergedRegion(region1);
//			HSSFCell cell2 = row2.createCell((short)0);
//			cell2.setCellValue("非工单领（退）料申请单");
//			cell2.setCellStyle(style1);
//			
//			HSSFRow row3 = sheet.createRow((short)2);//建立新行
//			HSSFCell c11 = row3.createCell((short)0);
//			c11.setCellStyle(style2);
//			HSSFCell c12 = row3.createCell((short)1);
//			c12.setCellValue("部门：");
//			c12.setCellStyle(style2);
//			HSSFCell c13 = row3.createCell((short)2);
//			c13.setCellStyle(style2);
//			HSSFCell c14 = row3.createCell((short)3);
//			c14.setCellStyle(style2);
//			HSSFCell c15 = row3.createCell((short)4);
//			c15.setCellStyle(style2);
//			HSSFCell c16 = row3.createCell((short)5);
//			c16.setCellStyle(style2);
//			HSSFCell c17 = row3.createCell((short)6);
//			c17.setCellValue("表单编号：");
//			c17.setCellStyle(style2);
//			HSSFCell c18 = row3.createCell((short)7);
//			c18.setCellStyle(style2);
//			HSSFCell c19 = row3.createCell((short)8);
//			c19.setCellStyle(style2);
//
//			HSSFRow row4 = sheet.createRow((short)3);//建立新行
//			Region region2 = new Region(3,(short) 0, 3, (short) 2);
//			Region region3 = new Region(3,(short) 3, 3, (short) 6);
//			Region region4 = new Region(3,(short) 7, 3, (short) 8);
//			sheet.addMergedRegion(region2);
//			sheet.addMergedRegion(region3);
//			sheet.addMergedRegion(region4);
//			HSSFCell c20= row4.createCell((short)0);
//			c20.setCellValue("领（退）料单号："+proget.getGetProCode());
//			c20.setCellStyle(style3);
//			row4.createCell((short) 1).setCellStyle(style3);
//			row4.createCell((short) 2).setCellStyle(style3);
//			HSSFCell c21= row4.createCell((short)3);
//			c21.setCellValue("系统单号："+(proget.getOriCode()==null?"":proget.getOriCode()));
//			c21.setCellStyle(style3);
//			row4.createCell((short) 4).setCellStyle(style3);
//			row4.createCell((short) 5).setCellStyle(style3);
//			row4.createCell((short) 6).setCellStyle(style3);
//			HSSFCell c22= row4.createCell((short)7);
//			c22.setCellValue("日期："+new SimpleDateFormat("yyyy-MM-dd").format(proget.getDctime()));
//			c22.setCellStyle(style3);
//			row4.createCell((short) 8).setCellStyle(style3);
//
//			HSSFRow row5 = sheet.createRow((short)4);//建立新行
//			Region region5 = new Region(4,(short) 0, 4, (short) 6);
//			Region region6 = new Region(4,(short) 7, 4, (short) 8);
//			sheet.addMergedRegion(region5);
//			sheet.addMergedRegion(region6);
//			HSSFCell c23= row5.createCell((short)0);
//			c23.setCellValue("领/退原因说明："+proget.getRemark());
//			c23.setCellStyle(style3);
//			row5.createCell((short) 1).setCellStyle(style3);
//			row5.createCell((short) 2).setCellStyle(style3);
//			row5.createCell((short) 3).setCellStyle(style3);
//			row5.createCell((short) 4).setCellStyle(style3);
//			row5.createCell((short) 5).setCellStyle(style3);
//			row5.createCell((short) 6).setCellStyle(style3);
//			HSSFCell c24= row5.createCell((short)7);
//			c24.setCellValue("仓库：");
//			c24.setCellStyle(style3);
//			row5.createCell((short) 8).setCellStyle(style3);
//			
//			HSSFRow row6 = sheet.createRow((short)5);//建立新行
//			Region region7 = new Region(5,(short) 1, 5, (short) 2);
//			sheet.addMergedRegion(region7);			
//			HSSFCell cell3 = row6.createCell((short)0);
//			cell3.setCellValue("编号");
//			cell3.setCellStyle(style);		
//			HSSFCell cell4 = row6.createCell((short)1);
//			cell4.setCellValue("物料编码");
//			cell4.setCellStyle(style);		
//			row6.createCell((short) 2).setCellStyle(style);
//			HSSFCell cell5 = row6.createCell((short)3);
//			cell5.setCellValue("描述");
//			cell5.setCellStyle(style);		
//			HSSFCell cell6 = row6.createCell((short)4);
//			cell6.setCellValue("批次");
//			cell6.setCellStyle(style);		
//			HSSFCell cell7 = row6.createCell((short)5);
//			cell7.setCellValue("单位");
//			cell7.setCellStyle(style);		
//			HSSFCell cell8 = row6.createCell((short)6);
//			cell8.setCellValue("需用/退量");
//			cell8.setCellStyle(style);		
//			HSSFCell cell9 = row6.createCell((short)7);
//			cell9.setCellValue("实发/退量");
//			cell9.setCellStyle(style);		
//			HSSFCell cell10 = row6.createCell((short)8);
//			cell10.setCellValue("备注");
//			cell10.setCellStyle(style);
//			
//			for(int i=0;i<itemlist.size();i++){
//				HSSFRow row7 = sheet.createRow((short)(6+i));//建立新行
//				Region region8 = new Region(6+i,(short) 1, 6+i, (short) 2);  
//				sheet.addMergedRegion(region8);			
//				
//				sheet.setColumnWidth(0, 500);
//				HSSFCell c31 = row7.createCell((short)0);
//				c31.setCellStyle(style);
//				c31.setCellValue(i+1);
//				
//				sheet.setColumnWidth(1, 3500);
//				HSSFCell c32 = row7.createCell((short)1);
//				c32.setCellStyle(style);
//				c32.setCellValue(itemlist.get(i).getCode());
//				row7.createCell((short) 2).setCellStyle(style);
//				
//				sheet.setColumnWidth(3, 8500);
//				HSSFCell c33 = row7.createCell((short)3);
//				c33.setCellStyle(style);
//				c33.setCellValue(itemlist.get(i).getName()+";"+itemlist.get(i).getSpec());
//				
//				sheet.setColumnWidth(4, 3000);
//				HSSFCell c34 = row7.createCell((short)4);
//				c34.setCellStyle(style);
//				c34.setCellValue("");
//
//				sheet.setColumnWidth(5, 1800);
//				HSSFCell c35 = row7.createCell((short)5);
//				c35.setCellStyle(style);
//				c35.setCellValue(itemlist.get(i).getJunit());
//				
//				sheet.setColumnWidth(6, 3000);
//				HSSFCell c36 = row7.createCell((short)6);
//				c36.setCellStyle(style);
//				c36.setCellValue(itemlist.get(i).getJquantuty());
//				
//				sheet.setColumnWidth(7, 3300);
//				HSSFCell c37 = row7.createCell((short)7);
//				c37.setCellStyle(style);
//				c37.setCellValue("");
//				
//				sheet.setColumnWidth(8, 2500);
//				HSSFCell c38 = row7.createCell((short)8);
//				c38.setCellStyle(style);
//				c38.setCellValue("");
//			}
//			
//			HSSFRow row8 = sheet.createRow((short)(6+itemlist.size()));//建立新行
//			Region region8 = new Region(6+itemlist.size(),(short) 0, 6+itemlist.size(), (short) 2);
//			Region region9 = new Region(6+itemlist.size(),(short) 3, 6+itemlist.size(), (short) 6);
//			Region region10 = new Region(6+itemlist.size(),(short) 7, 6+itemlist.size(), (short) 8);
//			sheet.addMergedRegion(region8);			
//			sheet.addMergedRegion(region9);			
//			sheet.addMergedRegion(region10);			
//			HSSFCell cell11 = row8.createCell((short)0);
//			cell11.setCellValue("仓库");
//			cell11.setCellStyle(style);	
//			row8.createCell((short) 1).setCellStyle(style);
//			row8.createCell((short) 2).setCellStyle(style);			
//			HSSFCell cell12 = row8.createCell((short)3);
//			cell12.setCellValue("品管");
//			cell12.setCellStyle(style);	
//			row8.createCell((short) 4).setCellStyle(style);
//			row8.createCell((short) 5).setCellStyle(style);
//			row8.createCell((short) 6).setCellStyle(style);	
//			HSSFCell cell13 = row8.createCell((short)7);
//			cell13.setCellValue("领（退）料部门");
//			cell13.setCellStyle(style);	
//			row8.createCell((short) 8).setCellStyle(style);	
//			
//			HSSFRow row9 = sheet.createRow((short)(7+itemlist.size()));//建立新行
//			Region region11 = new Region(7+itemlist.size(),(short) 0, 7+itemlist.size(), (short) 1);
//			Region region12 = new Region(7+itemlist.size(),(short) 5, 7+itemlist.size(), (short) 6);
//			sheet.addMergedRegion(region11);			
//			sheet.addMergedRegion(region12);		
//			HSSFCell cell14 = row9.createCell((short)0);
//			cell14.setCellValue("主管");
//			cell14.setCellStyle(style);		
//			row9.createCell((short) 1).setCellStyle(style);			
//			HSSFCell cell15 = row9.createCell((short)2);
//			cell15.setCellValue("经办");
//			cell15.setCellStyle(style);			
//			HSSFCell cell16 = row9.createCell((short)3);
//			cell16.setCellValue("主管");
//			cell16.setCellStyle(style);		
//			HSSFCell cell17 = row9.createCell((short)4);
//			cell17.setCellValue("");
//			cell17.setCellStyle(style);					
//			HSSFCell cell18 = row9.createCell((short)5);
//			cell18.setCellValue("经办");
//			cell18.setCellStyle(style);	
//			row9.createCell((short) 6).setCellStyle(style);	
//			HSSFCell cell19 = row9.createCell((short)7);
//			cell19.setCellValue("主管");
//			cell19.setCellStyle(style);		
//			HSSFCell cell20 = row9.createCell((short)8);
//			cell20.setCellValue("经办");
//			cell20.setCellStyle(style);	
//
//			HSSFRow row10 = sheet.createRow((short)(8+itemlist.size()));//建立新行
//			Region region13 = new Region(8+itemlist.size(),(short) 0, 8+itemlist.size(), (short) 1);
//			Region region14 = new Region(8+itemlist.size(),(short) 5, 8+itemlist.size(), (short) 6);
//			sheet.addMergedRegion(region13);			
//			sheet.addMergedRegion(region14);	
//			sheet.setColumnWidth(0, 2750);				
//			HSSFCell cell21 = row10.createCell((short)0);
//			cell21.setCellValue("");
//			cell21.setCellStyle(style);	
//			row10.createCell((short) 1).setCellStyle(style);			
//			HSSFCell cell22 = row10.createCell((short)2);
//			cell22.setCellValue("");
//			cell22.setCellStyle(style);			
//			HSSFCell cell23 = row10.createCell((short)3);
//			cell23.setCellValue("");
//			cell23.setCellStyle(style);		
//			HSSFCell cell24 = row10.createCell((short)4);
//			cell24.setCellValue("");
//			cell24.setCellStyle(style);					
//			HSSFCell cell25 = row10.createCell((short)5);
//			cell25.setCellValue("");
//			cell25.setCellStyle(style);		
//			row10.createCell((short) 6).setCellStyle(style);
//			HSSFCell cell26 = row10.createCell((short)7);
//			cell26.setCellValue("");
//			cell26.setCellStyle(style);		
//			HSSFCell cell27 = row10.createCell((short)8);
//			cell27.setCellValue("");
//			cell27.setCellStyle(style);
//			
//			HSSFRow row111 = sheet.createRow((short)(9+itemlist.size()));//建立新行			
//			HSSFCell cell28 = row111.createCell((short)0);
//			cell28.setCellValue("");
//			cell28.setCellStyle(style2);				
//			HSSFCell cell29 = row111.createCell((short)1);
//			cell29.setCellValue("第一联仓库");
//			cell29.setCellStyle(style2);			
//			HSSFCell cell30 = row111.createCell((short)2);
//			cell30.setCellValue("");
//			cell30.setCellStyle(style2);		
//			HSSFCell cell31 = row111.createCell((short)3);
//			cell31.setCellValue("第二联财务   第三联领（退）料部门");
//			cell31.setCellStyle(style2);					
//			HSSFCell cell32 = row111.createCell((short)4);
//			cell32.setCellValue("");
//			cell32.setCellStyle(style2);		
//			HSSFCell cell33 = row111.createCell((short)5);
//			cell33.setCellValue("");
//			cell33.setCellStyle(style2);		
//			HSSFCell cell34 = row111.createCell((short)6);
//			cell34.setCellValue("");
//			cell34.setCellStyle(style2);	
//			HSSFCell cell35 = row111.createCell((short)7);
//			cell35.setCellValue("保存期限:15年");
//			cell35.setCellStyle(style2);	
//			HSSFCell cell36 = row111.createCell((short)8);
//			cell36.setCellValue("");
//			cell36.setCellStyle(style2);
//			
//		}
//		response.setContentType("text/html;charset=UTF-8");
//		response.reset();
//		response.setContentType("application/ms-excel");
//	
//		String fileNameDisplay = "非工单领料申请单"+ proget.getGetProCode();
//		try {
//			fileNameDisplay = new String(fileNameDisplay.getBytes("GBK"),
//					"iso-8859-1");
//		} catch (UnsupportedEncodingException e1) {
//			e1.printStackTrace();
//		}
//		fileNameDisplay = fileNameDisplay.replace(" ", "%20");
//		response.addHeader("Content-Disposition", "attachment;filename="
//				+ fileNameDisplay + ".xls");
//		
//		OutputStream fout = null;
//		try {
//			fout = response.getOutputStream();
//			wb.write(response.getOutputStream());
//			fout.flush();
//			fout.close();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
	@RequestMapping(value = "/exportExcel")
	public void printer(HttpServletRequest request, HttpServletResponse response) throws Exception{
		try {
				String id = request.getParameter("id");
				LogicProGetApplyDO pg=new LogicProGetApplyDO();
				List<LogicProGetApplyItemDO> itemlist=new ArrayList<LogicProGetApplyItemDO>();
				if(!"".equals(id)&&id!=null){
					pg =logicProGetApplyService.findListById(id);
				}
				if(pg.getId()!=null){
					SearchConditions scs = new SearchConditions();
					scs.addCondition("get_pro_id", pg.getId(),SearchCondition.OP_EQUAL);
					scs.setLimitPage(false);
					scs.setRemovedProperty(null);
					scs.setOrderBy("code asc");
					itemlist =logicProGetApplyItemService.findListByExample(scs).getResults();
					if(itemlist!=null){
						int k = 1;
						for (LogicProGetApplyItemDO lApplyItemDO : itemlist) {
								lApplyItemDO.setId(k+"");
								if(lApplyItemDO.getName()!=null && lApplyItemDO.getCode()!=null){
									lApplyItemDO.setSpec(";"+lApplyItemDO.getSpec());
								}else{
									lApplyItemDO.setSpec(lApplyItemDO.getSpec());
								}
								k++;
							}
						}
					}
				if(itemlist.size()<11){
					int s = 11-itemlist.size();
					int n =itemlist.size();
					for (int i = 0; i < s; i++) {
						LogicProGetApplyItemDO item = new LogicProGetApplyItemDO();
						item.setId(n+1+i+"");
						itemlist.add(item);
					}
				}
				request.setCharacterEncoding("utf-8");
				response.setContentType("application/vnd.ms-excel;charset=utf-8"); 
//				String fileNameDisplay = "采购入库单";
//				try {
//					fileNameDisplay = new String(fileNameDisplay.getBytes("GBK"),
//							"iso-8859-1");
//				} catch (UnsupportedEncodingException e1) {
//					e1.printStackTrace();
//				}
				response.setHeader("Content-disposition", "attachment;filename="+pg.getGetProCode()+".xls");
				OutputStream os= response.getOutputStream(); 
		//		Map<String,Object> pMap = request.getParameterMap();
		//		List<Map> data = new ArrayList<Map>();
				XLSTransformer transformer = new XLSTransformer();
			    StringBuffer file=new StringBuffer(request.getRealPath("/"));;
				file.append("/views/printer/excelTemplate/progetapply.xls");
				Map<String, Object> map = new HashMap<String,Object>();
				map.put("pg", pg);
				map.put("item", itemlist);
				Workbook book= transformer.transformXLS(new FileInputStream(file.toString()), map);    						
					book.write(os);				
					os.flush();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
